home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
333_01
/
awk.h
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-18
|
18KB
|
542 lines
/***************************************************************************/
/* */
/* awk.h -- Definitions for gawk. */
/* */
/* Copyright (C) 1986 Free Software Foundation */
/* Written by Paul Rubin, August 1986 */
/* */
/***************************************************************************/
/* */
/* GAWK is distributed in the hope that it will be useful, but WITHOUT ANY */
/* WARRANTY. No author or distributor accepts responsibility to anyone */
/* for the consequences of using it or for whether it serves any */
/* particular purpose or works at all, unless he says so in writing. */
/* Refer to the GAWK General Public License for full details. */
/* */
/* Everyone is granted permission to copy, modify and redistribute GAWK, */
/* but only under the conditions described in the GAWK General Public */
/* License. A copy of this license is supposed to have been given to you */
/* along with GAWK so you can know your rights and responsibilities. It */
/* should be in a file named COPYING. Among other things, the copyright */
/* notice and this notice must be preserved on all copies. */
/* */
/* In other words, go ahead and share GAWK, but don't try to stop */
/* anyone else from sharing it farther. Help stamp out software hoarding! */
/* */
/***************************************************************************/
#ifndef AWK_H
#define AWK_H
#define AWKNUM double
#include "regex.h"
#include <ctype.h>
#define is_identchar(c) (isalnum(c) || (c) == '_')
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include "obstack.h"
#define PROFILER TRUE
#if PROFILER
#define STATIC
#else
#define STATIC static
#endif
#define EOS '\0'
#define FPTR void far *
#if defined(__POWERC)
#define NEAR
#define PASCAL
#define CDECL
#define VOID int
#else
#define NEAR near
#define PASCAL pascal
#define CDECL cdecl
#define VOID void
#endif
#define TABSTOPS 8
#define MAXDIM(array) (sizeof(array) / sizeof(array[0]))
#define MAX_SUBSCRIPT_LEN 80
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
typedef int BOOL;
/* illegal node entry */
#define NODE_ILLEGAL 0
/* binary operators - lnode and rnode are the expressions to work on */
#define NODE_EXPONENTIAL 1
#define NODE_TIMES 2
#define NODE_QUOTIENT 3
#define NODE_MOD 4
#define NODE_PLUS 5
#define NODE_MINUS 6
#define NODE_COND_PAIR 7
#define NODE_SUBSCRIPT 8
#define NODE_CONCAT 9
/* unary operators - subnode is the expression to work on */
#define NODE_PREINCREMENT 10
#define NODE_PREDECREMENT 11
#define NODE_POSTINCREMENT 12
#define NODE_POSTDECREMENT 13
#define NODE_UNARY_MINUS 14
#define NODE_FIELD_SPEC 15
/* assignment operators - lnode is the var to assign to rnode is the exp */
#define NODE_ASSIGN 16
#define NODE_ASSIGN_EXPONENTIAL 17
#define NODE_ASSIGN_TIMES 18
#define NODE_ASSIGN_QUOTIENT 19
#define NODE_ASSIGN_MOD 20
#define NODE_ASSIGN_PLUS 21
#define NODE_ASSIGN_MINUS 22
/* boolean binary operators - lnode and rnode are expressions */
#define NODE_AND 23
#define NODE_OR 24
/* relational binary operators - lnode and rnode are exp to comapre */
#define NODE_EQUAL 25
#define NODE_NOTEQUAL 26
#define NODE_LESS 27
#define NODE_GREATER 28
#define NODE_LEQ 29
#define NODE_GEQ 30
/* relational unary operators - subnode is the expression to operate on */
#define NODE_NOT 31
/* match operators - lnode is an exp, rnode is a regular expression */
#define NODE_MATCH 32
#define NODE_NOMATCH 33
/* data items */
#define NODE_STRING 34 /* stptr and stlen */
#define NODE_TEMP_STRING 35 /* stptr and stlen */
#define NODE_NUMBER 36 /* numbr */
/* program structures */
#define NODE_RULE_LIST 37 /* lnode is rule, rnode rest of list */
#define NODE_RULE_NODE 38 /* lnode is cond, rnode is statement */
#define NODE_STATEMENT_LIST 39 /* lnode is stmt, rnode is more list */
#define NODE_IF_BRANCHES 40 /* lnode is TRUE side, rnode is FALSE */
#define NODE_EXPRESSION_LIST 41 /* lnode is an exp, rnode is more list */
/* keywords */
#define NODE_K_BEGIN 42 /* nothing on either side */
#define NODE_K_END 43 /* nothing on either side */
#define NODE_K_IF 44 /* lnode is cond, rnode is if_branches */
#define NODE_K_WHILE 45 /* lnode is cond, rnode stuff to run */
#define NODE_K_FOR 46 /* lnode is for_struct, rnode run stuff */
#define NODE_K_ARRAYFOR 47 /* lnode is for_struct, rnode run stuff */
#define NODE_K_BREAK 48 /* nothing on either side */
#define NODE_K_CONTINUE 49 /* nothing on either side */
#define NODE_K_PRINT 50 /* lnode is exp_list, rnode is redirect */
#define NODE_K_PRINTF 51 /* lnode is exp_list, rnode is redirect */
#define NODE_K_NEXT 52 /* nothing on either side */
#define NODE_K_EXIT 53 /* subnode is return value, or NULL */
#define NODE_K_DELETE 54 /* lnode is symbol, rnode is subscript */
#define NODE_GETLINE 55 /* lnode is var, rnode is redirect */
/* I/O redirection for print statements */
#define NODE_REDIRECT_INPUT 56 /* subnode is where to redirect */
#define NODE_REDIRECT_OUTPUT 57 /* subnode is where to redirect */
#define NODE_REDIRECT_APPEND 58 /* subnode is where to redirect */
#define NODE_REDIRECT_PIPE 59 /* subnode is where to redirect */
/* variables */
#define NODE_VAR 60 /* rnode is value, lnode array stuff */
#define NODE_VAR_ARRAY 61 /* array is ptr to elements, asize = # */
/* builtin functions - subnode is exp_list, proc is function to call */
#define NODE_BUILTIN 62
/* line range pattern */
#define NODE_LINE_RANGE 63
/* conditional expression */
#define NODE_CONDEXP 64 /* lnode is cond, rnode is cond_branches*/
#define NODE_CONDEXP_BRANCHES 65 /* lnode is exp if TRUE, rnode if FALSE */
/* regular expression */
#define NODE_REGEXP 66
/* membership conditional */
#define NODE_MEMBER_COND 67
typedef struct exp_node
{
int type;
union
{
struct
{
struct exp_node *lptr;
union
{
struct exp_node *rptr;
struct exp_node *(PASCAL *pptr)(struct exp_node *);
REPAT_BUFFER *preg;
struct for_loop_header *hd;
struct ahash **av;
int r_ent; /* range entered (jfw) */
} r;
} nodep;
struct
{
struct exp_node **ap;
int as;
} ar;
struct
{
char *sp;
int slen, sref;
} str;
AWKNUM fltnum;
} sub;
} NODE;
#define lnode sub.nodep.lptr
#define rnode sub.nodep.r.rptr
#define subnode lnode
#define proc sub.nodep.r.pptr
#define reexp lnode
#define rereg sub.nodep.r.preg
#define forsub lnode
#define forloop sub.nodep.r.hd
#define array sub.ar.ap
#define arrsiz sub.ar.as
#define stptr sub.str.sp
#define stlen sub.str.slen
#define stref sub.str.sref
#define numbr sub.fltnum
#define var_value lnode
#define var_array sub.nodep.r.av
#define condpair lnode
#define triggered sub.nodep.r.r_ent
#define HASHSIZE 101
#define ASSOC_HASHSIZE 29
#define STIR_BITS(n) ((n) << 5 | (((n) >> 27) & 0x1f))
#define HASHSTEP(old, c) ((old << 1) + c)
#define MAKE_POS(v) (((v) < 0) ? -(v) : (v))
/* the following defines are used in calls to assoc_lookup() to advise the */
/* function of the type of action desired on the subscripted variable. */
#define ASSOC_CREATE 0 /* if var doesn't exist, create it */
#define ASSOC_TEST 1 /* test if var exists, don't create */
#define ASSOC_DELE